﻿using NiceComponents.MulPages.Events;
using Stylet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NiceComponents.MulPages.Pages
{
    public class ShellViewModel : Conductor<IScreen>.Collection.OneActive
    {
        private readonly IWindowManager _windowManager;
        private readonly IViewFactory _viewFactory;

        public ShellViewModel(IWindowManager windowManager, IViewFactory viewFactory)
        {
            _windowManager = windowManager;
            _viewFactory = viewFactory;
        }

        protected override void OnInitialActivate()
        {
            base.OnInitialActivate();
            this.Bind(s => SelectedMenuIndex, (o, e) => SelectedMenuIndexChanged());
        }

        public List<string> Menus { get; set; } = new List<string> { "Page1", "Page2" };
        public int SelectedMenuIndex { get; set; } = -1;

        private void SelectedMenuIndexChanged()
        {
            switch (SelectedMenuIndex)
            {
                case 0: ActivateItem(Page1View ?? (Page1View = _viewFactory.Page1ViewModel())); break;
                case 1: ActivateItem(Page2View ?? (Page2View = _viewFactory.Page2ViewModel())); break;
            }
        }             

        private Page1ViewModel Page1View;
        private Page2ViewModel Page2View;
       

        public void ShowDialog()
        {
            var dialog = new InputDialogViewModel
            {
                InputString = "your name"
            };

            if (_windowManager.ShowDialog(dialog)==true)
            {
                Debug.WriteLine($"You Input:{dialog.InputString}");
            }                       
        }
    }
}
